package com.scwatch.core.web.back;

import com.scwatch.common.web.Servlets;
import com.scwatch.core.constant.Constants;
import com.scwatch.core.domain.OperationLog;
import com.scwatch.core.service.OperationLogService;
import com.scwatch.core.support.Context;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 操作日志
 */
@Controller
@RequestMapping("/core/operation_log")
public class OperationLogController {
    private static final Logger logger = LoggerFactory.getLogger(OperationLogController.class);

    /**
     * 操作日志查询
     * @param pageable 分页对象
     * @param request 请求对象
     * @param modelMap
     * @return 结果页面
     */
    @RequiresPermissions("core:operation_log:list")
    @RequestMapping("list.do")
    public String list(@PageableDefault(sort = "id",direction = Sort.Direction.DESC) Pageable pageable,
                       HttpServletRequest request, org.springframework.ui.Model modelMap) {
        Integer siteId= Context.getCurrentSiteId();
        Map<String, String[]> params = Servlets.getParamValuesMap(request, Constants.SEARCH_PREFIX);
        Page<OperationLog> pagedList = service.findAll(siteId, params, pageable);
        modelMap.addAttribute("pagedList", pagedList);
        return "core/operationlog/operation_log";
    }

    @Autowired
    private OperationLogService service;

}
